package com.example.geomanager;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class PointsTracer implements Runnable {
	private MapView mapView;
	private MapController controller;
	private List<Overlay> overlays;
	private int currentTracingPoint;
	
	public PointsTracer(MapView view)
	{
		mapView = view;
		controller = mapView.getController();
		overlays = mapView.getOverlays();
	}
	
	GeoPoint getGeoPointFromOverlay(int id)
	{
		PinpointItemizedOverlay overlay = (PinpointItemizedOverlay) overlays.get(id);
		return overlay.getItem(0).getPoint();
	}
	
	public void startTracing()
	{
		controller.setZoom(18);
		currentTracingPoint = 0;
		controller.animateTo(getGeoPointFromOverlay(0), this);
	}

	public void run()
	{
		currentTracingPoint++;
		if (currentTracingPoint < overlays.size())
			controller.animateTo(getGeoPointFromOverlay(currentTracingPoint), this);
	}
}
